home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / gt_power / gtover11.zip / GTOVER.C next >
Text File  |  1989-04-14  |  7KB  |  248 lines

  1. /*
  2.  
  3. GTOVER -- GT Override
  4.  
  5. Version 1.1  (4/14/89)
  6. Written by Bob Quinlan of Austin, TX, USA
  7.  
  8. Copyright 1989 by Bob Quinlan
  9.  
  10. Compatible with GT versions 13 and 14
  11.  
  12.  
  13. This program can be used to set up non-hierarchic security within GT. 
  14. You can determine on a user-by-user basis who you want to have access to 
  15. each file area, message area, and door.  The program accomplishes this 
  16. by modifying entries in GTDIR.BBS, GTMDIR.BBS, and GTDDIR.BBS to show 
  17. the current user's access level.  GT's normal security handles all users
  18. who are not listed in the override file.  Normal security also applies 
  19. to all areas and doors which are not specifically overridden.
  20.  
  21. GTOVER normally gets its override information from a file called 
  22. OVERRIDE.BBS.  You can specify another file name on the command line if 
  23. you prefer.  You can also include a path as part of the filename.  If no 
  24. path is specified and the file is not in the default directory GTOVER 
  25. will look in the GTPATH directory for it.
  26.  
  27. You need to set the override file up as a text file containing user 
  28. names and their associated security overrides.  All usernames must start 
  29. at the beginning of a line.  Lines which begin with a space are assumed 
  30. to be continuations of the previous user's information.  The username 
  31. must be immediately followed by a comma, semicolon, or carriage return.  
  32. Overrides are specified by an initial letter followed by a number.  The 
  33. letters are "F" for file, "M" for message, and "D" for door.  The number 
  34. represents the file, message, or door number which is to be overridden.  
  35. Any line in the corresponding security file which does not have a space 
  36. in line one is counted as an entry.  Overrides may be separated by 
  37. spaces, commas, semicolons, or carriage returns.
  38.  
  39. Here is a sample OVERRIDE.BBS:
  40.  
  41. Bob Quinlan, F2 M6 M7 D4
  42. John Doe
  43.   F3
  44.   M5
  45.  
  46. This file would give Bob Quinlan automatic access to the file area #2,
  47. message areas #6 and #7, and door #4 irregardless of the access level
  48. normally required.  It would also give John Doe automatic access to file
  49. area #3 and message area #5.
  50.  
  51. Special Note:  This program will not give a user access to message areas
  52. from which they have been banned, nor will it override an asterisk
  53. specification on a message area.  It simply alters the level of the
  54. areas so that they appear on the user's list.
  55.  
  56. To use GTOVER you simply execute it in the GTLOGON.BAT.  This will alter
  57. the security files as necessary for the current user.  Make sure that
  58. you restore GTDIR.BBS, GTMDIR.BBS, and GTDDIR.BBS from unmodified copies
  59. during the GTLOGOFF.BAT.  It is also a good idea to restore these files
  60. before starting GT so that special circumstances, such as a system
  61. reboot, will not compromise your security by leaving these files in
  62. their alterred states.
  63.  
  64. NOTICE:  You may use, copy, and distribute this program freely as long
  65. as you insure that both the executable and the documentation (.DOC)
  66. files are included in the distribution package.  The source code does
  67. not need to be included.  You may modify this program and document, so
  68. long as reasonable credit is given to the original author if a
  69. substantial portion of the original remains intact.  The author is not
  70. responsible for any losses which may occur either directly or indirectly
  71. as a result of using this program.
  72.  
  73. HISTORY:
  74. Version 1.1   (4/14/89) -- Handle cases where the access level is not
  75.                the first character on a line.  Accept a file 
  76.                            specification for the override file from the 
  77.                            command line.
  78. Version 1.0   (4/12/89) -- Original release.  Written in Turbo C.
  79.  
  80. */
  81.  
  82. #include <stdio.h>
  83. #include <stdlib.h>
  84. #include <string.h>
  85. #include <ctype.h>
  86. #include <dos.h>
  87.  
  88. #define MAXLINE 256
  89. #define MAXPATH 128
  90. #define PARAMS    8
  91.  
  92. FILE *pathopen (char *, char *, char *);
  93.  
  94.  
  95. main (int argc, char *argv[])
  96.  
  97. {
  98. char    gtpath[MAXPATH];
  99.  
  100. char    fields[MAXLINE];
  101. char    *gtuser[PARAMS];
  102. int    arg;
  103.  
  104. char    data[MAXLINE];
  105. char    line[MAXLINE];
  106.  
  107. FILE    *gtuser_fp;
  108. FILE    *override_fp;
  109.  
  110. FILE    *fp[3];
  111. fpos_t  pos;
  112. int     cur_file;
  113. int     count;
  114.  
  115. char    *token;
  116.  
  117. int     end_of_file = 0;
  118. int     found = 0;
  119.  
  120. int    i, j, k;
  121.  
  122. printf ("GTOVER 1.1 -- Copyright 1989 by Bob Quinlan (4/14/89)\n");
  123.  
  124. /*  Read and adapt GTPATH  */
  125. strcpy (gtpath, getenv ("GTPATH"));
  126. i = strlen (gtpath);
  127. if (--i >= 0)
  128.     if ((gtpath[i] != '\\') && (gtpath[i] != ':'))
  129.     strcat (gtpath, "\\");
  130.  
  131. /*  Read in values from GTUSER.BBS  */
  132. gtuser_fp = pathopen ("GTUSER.BBS", "r", gtpath);
  133. if (fgets (fields, MAXLINE, gtuser_fp) == NULL) {
  134.     fprintf (stderr, "GTOVER: Unable to read GTUSER.BBS\n");
  135.     exit (1);
  136.     }
  137. fclose (gtuser_fp);
  138.  
  139. /*  Parse access level and name from GTUSER.BBS  */
  140. arg = 0;
  141. gtuser[arg] = strtok (fields, " \n");
  142. while (!isupper (gtuser[arg][1]))
  143.     gtuser[++arg] = strtok (NULL, " \n");
  144.  
  145. /*  Reassemble username into one string  */
  146. for (i=2; i<arg; i++)
  147.     *(gtuser[i]-1) = ' ';
  148.  
  149. /*  Search OVERRIDE.BBS for this user  */
  150. if (argc > 1)
  151.     override_fp = pathopen (argv[1], "r", gtpath);
  152. else
  153.     override_fp = pathopen ("OVERRIDE.BBS", "r", gtpath);
  154. while (!end_of_file && !found)
  155.     if (fgets (data, MAXLINE, override_fp) == NULL)
  156.     end_of_file = 1;
  157.     else
  158.     if (*data != ' ') {
  159.         token = strtok (data, ";,\n");
  160.         if (strcmpi (gtuser[1], token) == 0)
  161.         found = 1;
  162.         }
  163.  
  164. if (found) {
  165.     fp[0] = pathopen ("GTDIR.BBS", "r+b", gtpath);
  166.     fp[1] = pathopen ("GTMDIR.BBS", "r+b", gtpath);
  167.     fp[2] = pathopen ("GTDDIR.BBS", "r+b", gtpath);
  168.  
  169.     while (found) {
  170.     /*  Parse file, message, and door overrides  */
  171.     token = strtok (NULL, " ;,\n");
  172.     while ((token == NULL) && found)
  173.         if (fgets (data, MAXLINE, override_fp) == NULL)
  174.         found = 0;
  175.         else
  176.         /*  Any line beginning with a space is a continuation  */
  177.         if (*data != ' ')
  178.             found = 0;
  179.         else
  180.             token = strtok (data, " ;,\n");
  181.     if (found) {
  182.         *token = tolower (*token);
  183.         if (*token == 'm')
  184.         cur_file = 1;
  185.         else if (*token == 'd')
  186.         cur_file = 2;
  187.         else
  188.         cur_file = 0;
  189.         if ((token = strpbrk (token, "0123456789")) == NULL)
  190.         count = 1;
  191.         else
  192.         count = atoi (token);
  193.  
  194.         /*  Read and modify  */
  195.         rewind (fp[cur_file]);
  196.         i = 0;
  197.         fgetpos (fp[cur_file], &pos);
  198.         while ((fgets (line, MAXLINE, fp[cur_file]) != NULL) &&
  199.           (i < count)) {
  200.         if (*line != ' ')
  201.             i++;
  202.         if (i == count) {
  203.             j = 0;
  204.             k = strlen (line);
  205.             while ((!isalnum(line[j++])) && (j < k))
  206.             pos++;
  207.             }
  208.         else
  209.             fgetpos (fp[cur_file], &pos);
  210.         }
  211.         if (i != count)
  212.         fprintf (stderr, "GTOVER: Bad Override Specification\n");
  213.         else {
  214.         fsetpos (fp[cur_file], &pos);
  215.         fputc (*gtuser[0], fp[cur_file]);
  216.         }
  217.         }
  218.     }
  219.  
  220.     for (cur_file=2; cur_file>=0; cur_file--)
  221.     fclose (fp[cur_file]);
  222.     }
  223.  
  224. fclose (override_fp);
  225.  
  226. return 0;
  227. }
  228.  
  229.  
  230. /*  Open file using GTPATH  */
  231.  
  232. FILE *pathopen (char *name, char *mode, char *gtpath) {
  233.  
  234. FILE *fp;
  235.  
  236. char path[MAXPATH];
  237.  
  238. if ((fp = fopen (name, mode)) == NULL) {
  239.     strcpy (path, gtpath);
  240.     strcat (path, name);
  241.     if ((fp = fopen (path, mode)) == NULL) {
  242.     fprintf (stderr, "GTOVER: Unable to open %s\n", name);
  243.     exit (1);
  244.     }
  245.     }
  246. return fp;
  247. }
  248.